//
//  DoomAppDelegate.m
//  MobileDoom
//
//  Created by Steven Troughton-Smith on 30/05/2008.
//  Copyright 2008 Glenstal. All rights reserved.
//

#import "DoomAppDelegate.h"
#import "AdMobView.h"
#include "iPhone_Routines_SDK.h"
#import "MPTVOutWindow.h"

@interface AdMobSingleAdView : UIView
{
	
}



@end

@implementation AdMobSingleAdView (DoomEx)

-(void)drawShineBackgroundWithBaseColor:(UIColor *)r
{
	[[UIColor clearColor] set];
	UIRectFill(self.bounds);
	
	//UIGraphicsGetCurrentContext();
	
	
	[[UIImage imageNamed:@"menu-bar-pressed.png"] drawInRect:self.bounds];
}

@end

@implementation MPVideoView (extended)  
- (void) addSubview: (UIView *) aView 
{ 
    [super addSubview:aView]; 
} 
@end 

@implementation DoomAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
	[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];	
	
#if ENABLE_TV_OUT	
	MPVideoView *vidView = [[MPVideoView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
	MPTVOutWindow *_tvWindow = [[MPTVOutWindow alloc] initWithVideoView:vidView];  
	[vidView addSubview:doomViewController.screenView];
	
	[_tvWindow makeKeyAndVisible];  
#endif
	
	window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  

	self.window = window;	
	[window makeKeyAndVisible];	
	[window addSubview:mainMenuController.view];
	
	
	UIView *_ad = [AdMobView requestAdWithDelegate:self];
	
	[_ad setFrame:CGRectMake(0, 0, 251, 48)];
	[adView addSubview:_ad];

	[window makeKeyAndVisible];
	
}

-(IBAction)play:(id)sender
{
	UIView *view = doomViewController.view;

	CGAffineTransform t;
	
	t = CGAffineTransformRotate (CGAffineTransformIdentity, (float)90/180*M_PI);

	view.frame = CGRectMake(-80,80, view.frame.size.width, view.frame.size.height);
	
	view.alpha = 0.0;
	[window addSubview:view];

	view.transform = CGAffineTransformScale(t, 1.3, 1.3);
	[UIView beginAnimations: nil context: nil];
    [UIView setAnimationDuration: 0.5];
	view.alpha = 1.0;
	view.transform = CGAffineTransformScale(t, 1.0, 1.0);
	[UIView commitAnimations];
	
	[self launch_game];
}

-(void)launch_game
{
	pthread_create(&game_tid, NULL, game_thread, NULL);
}

#pragma mark -
#pragma mark AdMobDelegate methods

- (NSString *)publisherId {
	return @"a14921d6d8880f6"; // this should be prefilled; if not, get it from www.admob.com
}


- (UIColor *)adBackgroundColor {
	return [UIColor colorWithRed:16.0/255.0 green:8.0/255.0 blue:8.0/255.0 alpha:1.0];//[UIColor colorWithRed:0.498 green:0.565 blue:0.667 alpha:1]; // this should be prefilled; if not, provide a UIColor
}

- (UIColor *)adTextColor {
	return [UIColor whiteColor]; // this should be prefilled; if not, provide a UIColor
}

- (BOOL)mayAskForLocation {
	return NO; // this should be prefilled; if not, see AdMobProtocolDelegate.h for instructions
}

- (void)didReceiveAd:(AdMobView *)adView {
	NSLog(@"AdMob: Did receive ad");
}

- (void)didFailToReceiveAd:(AdMobView *)adView {
	NSLog(@"AdMob: Did fail to receive ad");
}

- (BOOL)useTestAd {
	return NO;
}

- (void)dealloc {
	[window release];
	[super dealloc];
}
@end
